﻿using System;
using System.Collections.Generic;
using System.ComponentModel.Design.Serialization;
using System.Linq;
using System.Text.Json;
using System.Text.Json.Serialization;
using System.Threading;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;

namespace NETCORE.AsyncProd.Controllers
{
    [Route("api/[controller]")]
    [ApiController]
    public class TestController : ControllerBase
    {
        public TestController() { }


        [HttpGet]
        [Route("Get1")]
        public async Task<JsonResult> Get1Async()
        {
            Console.ForegroundColor = ConsoleColor.Red;


            Console.WriteLine("trunk run 1");

            var p1 = await GetPerson1();

            Console.WriteLine("trunk run 2");


            Console.ResetColor();

            return new JsonResult(p1);
        }




        private Task<string> GetPerson1()
        {
            return Task.Run(() =>
            {
                Console.WriteLine("t1: start ："+DateTime.Now.ToLongTimeString());

                Task.Delay(5000).Wait();
                
                Console.WriteLine("t1: end：" + DateTime.Now.ToLongTimeString());

                return "t1 result";
            });
        }
    }
}
